/*
    Heart of Gold engine management system
    Copyright (C) 2004 Heart of Gold development team

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**     @author Greg Feigenson
 * A general purpose message class for the HOG_Component
 * class and the HogMessenger to be able to communicate.
 *
 * Overwrote the equals and toString for specificity
 */

package com.heartOfGold.model;

import java.util.Iterator;
import java.util.Vector;


public class Message extends ModelMessage {
    private Vector<Object> args;

    /* Constructors */
    public Message() {
        super();
        args = new Vector<Object>();
        return;
    }

    public Message(final String HOG_ComponentID) {
        super(HOG_ComponentID);
        args = new Vector<Object>();
        return;
    }

    /* Public Methods */
    public void addArg(final Object arg) {
        args.addElement(arg);
        return;
    }

    public Iterator<Object> getArgs() {
        return args.iterator();
    }

    /* Overridden methods form parent classes */
    public String toString() {
        String output = "HogMessage ID: (" + getID() + ") Args: (";
        Iterator<Object> it = getArgs();
        output += it.next();
        while (it.hasNext()) {
            output += ", " + it.next();
        }
        output += ")";
        return output;
    }

    public boolean equals(final Message comparitor) {
        /*
         * Message: ========= String ID Vector (of strings) Args
         */
        if (!comparitor.getID().equals(this.getID())) {
            return false;
        }
        Iterator<Object> ourArgs = this.getArgs();
        Iterator<Object> comparitorArgs = comparitor.getArgs();
        while (comparitorArgs.hasNext() && ourArgs.hasNext()) {
            if (!comparitorArgs.next().equals(ourArgs.next())) {
                return false;
            }
        }
        return true;
    }
}
